package com.core.common.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.stereotype.Component;

/**
 * @program: maobao-parent
 * @description: 用于非http请求异常统一处理
 * @author: honglei
 * @create: 2022-06-08 10:10
 */
@Slf4j
@Aspect
@Component
public class ExceptionAspect {

//    @Autowired
//    IMsgService iMsgService;

    @Pointcut("@annotation(com.core.common.annotation.ExceptionAdvice)")
    public void logPointcut(){

    }

    @Before("logPointcut()")
    public void  methodBefore(JoinPoint joinPoint){

    }


    @AfterReturning(returning = "o",pointcut = "logPointcut()")
    public void methodAfterReturning(Object o){

    }


    @AfterThrowing(pointcut = "logPointcut()",throwing = "e")
    public void logThrowing(JoinPoint joinPoint,Throwable e){
        log.info("***************抛出异常***************");
        if (e instanceof UncategorizedSQLException){
//            iMsgService.sendErrorMsg(e.getMessage());
            log.error(e.getMessage());
        }
        log.info("请求类方法:"+joinPoint.getSignature().getName());
        log.info("\n");
    }
}
